package cn.edu.xhu.library_management.department.test;

import cn.edu.xhu.library_management.department.entity.LmClass;
import cn.edu.xhu.library_management.department.entity.LmMajor;
import cn.edu.xhu.library_management.department.service.ClassService;
import cn.edu.xhu.library_management.department.service.MajorService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;
import java.util.Random;

/**
 * @Author: MMJ
 * @Date: 2023 - 03 - 13
 * @Description:
 */
@SpringBootTest
public class A {
    @Autowired
    private ClassService classService;
    @Autowired
    private MajorService majorService;

    @Test
    public void addClass(){
        Random random = new Random();

        List<LmMajor> majors = majorService.findAllMajor();
        majors.forEach(major -> {
//            int year = random.nextInt(5)+(2023-5);
            for (int i = 2018; i < 2022; i++) {
                int n = random.nextInt(4-2)+2;
                for (int j = 0; j < n; j++) {
                    classService.addClass(new LmClass(null,i,j+1,major.getId()));
                }
            }


        });

//        service.addClass(new LmClass(null,2018,2,2));
    }
}
